var JSON;
if (!JSON) {
    JSON = {}
} (function() {
    function f(n) {
        return n < 10 ? "0" + n: n
    }
    if (typeof Date.prototype.toJSON !== "function") {
        Date.prototype.toJSON = function(key) {
            return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + f(this.getUTCMonth() + 1) + "-" + f(this.getUTCDate()) + "T" + f(this.getUTCHours()) + ":" + f(this.getUTCMinutes()) + ":" + f(this.getUTCSeconds()) + "Z": null
        };
        String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function(key) {
            return this.valueOf()
        }
    }
    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
    escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
    gap, indent, meta = {
        "\b": "\\b",
        "\t": "\\t",
        "\n": "\\n",
        "\f": "\\f",
        "\r": "\\r",
        '"': '\\"',
        "\\": "\\\\"
    },
    rep;
    function quote(string) {
        escapable.lastIndex = 0;
        return escapable.test(string) ? '"' + string.replace(escapable,
        function(a) {
            var c = meta[a];
            return typeof c === "string" ? c: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice( - 4)
        }) + '"': '"' + string + '"'
    }
    function str(key, holder) {
        var i, k, v, length, mind = gap,
        partial, value = holder[key];
        if (value && typeof value === "object" && typeof value.toJSON === "function") {
            value = value.toJSON(key)
        }
        if (typeof rep === "function") {
            value = rep.call(holder, key, value)
        }
        switch (typeof value) {
        case "string":
            return quote(value);
        case "number":
            return isFinite(value) ? String(value) : "null";
        case "boolean":
        case "null":
            return String(value);
        case "object":
            if (!value) {
                return "null"
            }
            gap += indent;
            partial = [];
            if (Object.prototype.toString.apply(value) === "[object Array]") {
                length = value.length;
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value) || "null"
                }
                v = partial.length === 0 ? "[]": gap ? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]": "[" + partial.join(",") + "]";
                gap = mind;
                return v
            }
            if (rep && typeof rep === "object") {
                length = rep.length;
                for (i = 0; i < length; i += 1) {
                    if (typeof rep[i] === "string") {
                        k = rep[i];
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ": ": ":") + v)
                        }
                    }
                }
            } else {
                for (k in value) {
                    if (Object.prototype.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ": ": ":") + v)
                        }
                    }
                }
            }
            v = partial.length === 0 ? "{}": gap ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}": "{" + partial.join(",") + "}";
            gap = mind;
            return v
        }
    }
    if (typeof JSON.stringify !== "function") {
        JSON.stringify = function(value, replacer, space) {
            var i;
            gap = "";
            indent = "";
            if (typeof space === "number") {
                for (i = 0; i < space; i += 1) {
                    indent += " "
                }
            } else {
                if (typeof space === "string") {
                    indent = space
                }
            }
            rep = replacer;
            if (replacer && typeof replacer !== "function" && (typeof replacer !== "object" || typeof replacer.length !== "number")) {
                throw new Error("JSON.stringify")
            }
            return str("", {
                "": value
            })
        }
    }
    if (typeof JSON.parse !== "function") {
        JSON.parse = function(text, reviver) {
            var j;
            function walk(holder, key) {
                var k, v, value = holder[key];
                if (value && typeof value === "object") {
                    for (k in value) {
                        if (Object.prototype.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v
                            } else {
                                delete value[k]
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value)
            }
            text = String(text);
            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx,
                function(a) {
                    return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice( - 4)
                })
            }
            if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
                j = eval("(" + text + ")");
                return typeof reviver === "function" ? walk({
                    "": j
                },
                "") : j
            }
            throw new SyntaxError("JSON.parse")
        }
    }
} ());
$(document).ready(function() {
    var p = function(r, s) {
        var i = no_cache_url("include/zy_function.php");
        $.post(i, {
        	entry_id: dianexia.entry_id,
        	method: 'addFavoShop',
        	shop_id: r
        },
        function(t) {
            if (typeof s != "undefined") {
                s(t);
            }
        });
    };
    var k = function(r, s) {
    	var i = no_cache_url("include/zy_function.php");
        $.post(i, {
            entry_id: dianexia.entry_id,
            method: 'unFavoShop',
            shop_id: r
        },
        function(t) {
            if (typeof s != "undefined") {
                s(t);
            };
        });
    };
    var e = function(i) {
        p(i,
        function(r) {
            c();
            $("#restaurant-" + i).find(".favor-book").html('<span class="favor-icon"></span>');
            $("#restaurant-" + i).addClass("has-favor-icon");
            $self.hide();
            $self.next().show();
        });
    };
    var f = function(i) {
        k(i,
        function(r) {
            c();
            $("#restaurant-" + i).find(".favor-book").html("");
            $("#restaurant-" + i).removeClass("has-favor-icon");
            $self.hide();
            $self.prev().show();
        });
    };
    var o = function() {
        /*if (!dianexia.logined) {
            return false;
        }
        var i = no_cache_url(get_entry_url() + "/entry/favoredRestaurants");
        */
    };
    var c = function() {
      /*  var i = no_cache_url(get_entry_url() + "/entry/favoredBar");
        $.get(i, {
            entry_id: dianexia.entry_id
        },
        function(r) {
            $("#favored-bar #favored-restaurants").html(r);
        });*/
    };
    o();(function() {
        var i = false;
        $(".add-favor").live("click",
        function() {
            if (!login_modal_first()) {
                return false;
            }
            if (!i) {
                $("#modal-add-favor").modal({
                    keyboard: true,
                    backdrop: "static"
                });
                i = true;
            }
            $("#modal-add-favor").modal("show");
            var r = no_cache_url(get_entry_url() + "/entry/addFavor");
            $.get(r, {
                entry_id: dianexia.entry_id
            },
            function(s) {
                $("#modal-add-favor .modal-body").html(s)
            })
        });
        $("#modal-add-favor .modal-body .nav-tabs li a").live("click",
        function() {
            $(this).parent().siblings(".active").removeClass("active");
            $(this).parent().addClass("active");
            var r = "#modal-add-favor .modal-body #" + $(this).attr("class");
            $("#modal-add-favor .modal-body").find(".pill-content .in-tab-content").hide();
            $(r).show();
            return false
        });
        $("#modal-add-favor .modal-header .close").live("click",
        function() {
            $("#modal-add-favor").modal("hide");
            _gaq.push(["_trackEvent", "favor", "cancel", "1"]);
            return false;
        });
        $("#modal-add-favor").bind("hidden",
        function() {
            o();
            c();
        });
        $("#modal-add-favor input.checkbox").live("change",
        function() {
            var r = $(this).val();
            if (this.checked) {
                p(r);
            } else {
                k(r);
            }
        });
        $("#modal-add-favor .btn.complete").live("click",
        function() {
            $("#modal-add-favor").modal("hide");
            _gaq.push(["_trackEvent", "favor", "complete", "1"]);
            return false;
        });
    })(); 
    (function() {
        var i = null;
        $(".promoted-restaurants .restaurant-block, .more-restaurants .restaurant-block").live("mouseenter",
        function() {
            clearTimeout(i);
            var s = $(this);
            var r = s.attr("rel");
            
            s.find(".status-desc").hide();
            if (s.hasClass("has-favor-icon")) {
                s.find(".hover-un-favor").show();
            } else {
                s.find(".hover-add-favor").show();
            }
            i = setTimeout(function() {
                var x = s.offset().left + s.width() + 5;
                var w = s.offset().top - 10;
                if (x + 360 > $(window).width()) {
                    x = s.offset().left - 10 - 360;
                    $("#copy_dlg_restaurant").addClass("left").removeClass("right").css({
                        left: x,
                        top: w
                    }).show()
                } else {
                    $("#copy_dlg_restaurant").addClass("right").removeClass("left").css({
                        left: x,
                        top: w
                    }).show()
                }
                $("#copy_dlg_restaurant .detail").html(s.find(".line-hover-dlg").html());
                if (s.find(".huanbao-week-order").size() >= 1) {
                    var u = no_cache_url(get_entry_url() + "/restaurant/week_order");
                    var t = s.find(".huanbao-week-order").attr("rel");
                    var v = $(".huanbao-week-order");
                    $.get(u, {
                        id: t
                    },
                    function(y) {
                        v.find(".line-one").html(y)
                    })
                }
            },
            360)
        }).live("mouseleave",
        function() {
            var r = $(this);
            r.find(".status-desc").show();
            r.find(".hover-un-favor").hide();
            r.find(".hover-add-favor").hide();
            clearTimeout(i);
            $("#copy_dlg_restaurant .detail").html("");
            $("#copy_dlg_restaurant").hide()
        })
    })(); (function() {
        $(".favored-restaurants .restaurant-block").live("mouseenter",
        function() {
            $(this).find(".delete-action").show()
        }).live("mouseleave",
        function() {
            $(this).find(".delete-action").hide()
        });
        $(".favored-restaurants .restaurant-block .delete-action .delete").live("click",
        function() {
            var i = $(this).attr("rel");
            k(i,
            function(r) {
                c();
                $("#restaurant-" + i).find(".favor-book .favor-icon").hide();
                $("#restaurant-" + i).removeClass("has-favor-icon")
            });
            return false
        })
    })(); (function() {
        $(".hover-add-favor").live("click",
        function() {
        	 
            if (!login_modal_first()) {
                return false;
            }
           
            var i = $(this).attr("rel");
            var r = $(this);
           
            p(i,
            function(s) {
                c();
                
                $("#restaurant-" + i).find(".favor-book .favor-icon").show();
               
                $("#restaurant-" + i).addClass("has-favor-icon");
                r.hide();
                r.next().show();
            });
            return false;
        });
        $(".hover-un-favor").live("click",
        function() {
            var i = $(this).attr("rel");
            var r = $(this);
            k(i,
            function(s) {
                c();
                $("#restaurant-" + i).find(".favor-book .favor-icon").hide();
                $("#restaurant-" + i).removeClass("has-favor-icon");
                r.hide();
                r.prev().show();
            });
            return false;
        })
    })(); (function() {
        var t = function(u) {
            u.addClass("checked");
            u.find("input").attr("checked", true)
        };
        var s = function(u) {
            u.removeClass("checked");
            u.find("input").removeAttr("checked")
        };
        var r = function() {
            $(".filter-btn").removeClass("checked").find("input").removeAttr("checked");
            t($(".filter-btn input[value=tuijian]").parent())
        };
        r();
        $(".filter-btn").click(function() {
            $self = $(this);
            if ($self.find("input").val() == "tuijian") {
                $(".filter-btn").removeClass("checked").find("input").removeAttr("checked")
            } else {
                s($(".filter-btn input[value=tuijian]").parent())
            }
            if ($self.hasClass("checked")) {
                s($self)
            } else {
                t($self)
            }
            $(".promoted-restaurants #filted-table").remove();
            if ($("#filter-btn-wrapper .checked").size() < 1) {
                r();
                $(".promoted-restaurants .restaurant-list-table").show()
            } else {
                var u = JSON.parse(filterJson);
                var w = u.allRst;
                $("#filter-btn-wrapper .checked").each(function(x) {
                    var y = $(this).find("input").val();
                    var z = u[y];
                    w = $.grep(w,
                    function(A) {
                        return $.inArray(A, z) >= 0
                    })
                });
                var v = i(w);
                $(".promoted-restaurants .restaurant-list-table").hide().after($(v))
            }
        });
        var i = function(y) {
            var x = "<table class='restaurant-list-table' id='filted-table'><tbody>";
            var w = 0;
            var u = 5;
            $.each(y,
            function(A, B) {
                if ($("#restaurant-" + B).size() > 0) {
                    w++;
                    if (w % u == 1) {
                        x += "<tr>"
                    }
                    var z = "<td>" + $("#restaurant-" + B).parent().html() + "</td>";
                    x += z;
                    if (w % u == 0) {
                        x += "</tr>"
                    }
                }
            });
            var v = 0;
            if (w % u > 0) {
                v = u - w % u
            }
            if (v > 0) {
                for (var w = 0; w < v; w++) {
                    x += "<td></td>"
                }
                x += "</tr>"
            }
            x += "</tbody></table>";
            return x
        }
    })(); (function() {
        $(".restaurant-block").live("click",
        function(r) {
            var i = $(this).find(".restaurant-link");
            if (i.size() > 0) {
                window.open(i.attr("href"), "_blank");
                return false
            }
        })
    })();
    $(".tooltip-on").tooltip({
        delay: {
            show: 500,
            hide: 100
        },
        trigger: "hover"
    }); (function() {
        var i = null;
        $(".item").live("mouseenter",
        function() {
            var r = $(this);
            clearTimeout(i);
            i = setTimeout(function() {
                r.find(".extra-action-wrapper").show();
                r.find(".num-ratings").hide();
                if (r.hasClass("favored")) {
                    r.find(".hover-favor-food").hide();
                    r.find(".hover-un-favor-food").show()
                } else {
                    r.find(".hover-favor-food").show();
                    r.find(".hover-un-favor-food").hide()
                }
                r.find(".hover-food-link").show()
            },
            100)
        }).live("mouseleave",
        function() {
            clearTimeout(i);
            $(this).find(".num-ratings").show();
            $(this).find(".extra-action-wrapper").hide();
            $(this).find(".hover-favor-food").hide();
            $(this).find(".hover-un-favor-food").hide();
            $(this).find(".hover-food-link").hide()
        })
    })(); (function() {
        $(".hover-favor-food").live("click",
        function() {
            if (!login_modal_first()) {
                return false
            }
            var s = $(this);
            var t = s.attr("rel");
            var r = s.attr("rel");
            var i = get_entry_url() + "/food/favor";
            $.get(no_cache_url(i), {
                food_id: t,
                restaurant_id: r
            },
            function(u) {
                if (u >= 1) {
                    s.hide();
                    s.next().show();
                    $("#food-" + t).addClass("favored")
                }
            });
            return false
        });
        $(".hover-un-favor-food").live("click",
        function() {
            if (!login_modal_first()) {
                return false
            }
            var s = $(this);
            var t = s.attr("rel");
            var r = s.attr("rel");
            var i = get_entry_url() + "/food/unfavor";
            $.get(no_cache_url(i), {
                food_id: t,
                restaurant_id: r
            },
            function(u) {
                if (u >= 1) {
                    s.hide();
                    s.prev().show();
                    $("#food-" + t).removeClass("favored")
                }
            });
            return false
        })
    })();
    var l = $(".activity-banner .pic"),
    a = l.children(),
    q = false,
    j = 1;
    var h = '<ul class="num">';
    for (var g = 1; g <= a.length; g++) {
        h += "<li><a>" + g + "</a><span></span></li>"
    }
    h += "</ul>";
    $("#activity-slide").append(h);
    var d = $(".activity-banner .num li");
    var m = $("#slideshow_wrap").height();
    a.eq(a.length - 1).clone().prependTo(l);
    d.eq(0).addClass("current");
    function b() {
        if (!q) {
            q = true;
            d.eq(j).addClass("current").siblings().removeClass("current");
            j += 1;
            l.animate({
                top: -m * j
            },
            500,
            function() {
                if (j == a.length) {
                    j = 0;
                    l.css({
                        top: 0
                    })
                }
                q = false
            })
        }
    }
    var n = setInterval(b, 4000);
    d.hover(function() {
        l.stop(true, true);
        clearInterval(n);
        j = d.index($(this));
        b()
    },
    function() {
        n = setInterval(b, 4000);
        return false
    })
});